package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车接口")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车接口
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加购物车接口")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        return shoppingCartService.addShoppingCart(shoppingCartDTO);
    }

    /**
     * 查看购物车
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查看购物车接口")
    public Result<List<ShoppingCart>> list(){
        return shoppingCartService.list();
    }

    /**
     * 删除购物车中的一个商品
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    @ApiOperation(value = "删除购物车中的一个商品接口")
    public Result delete(@RequestBody ShoppingCartDTO shoppingCartDTO){
        return shoppingCartService.delete(shoppingCartDTO);
    }


    @DeleteMapping("/clean")
    @ApiOperation(value = "清空购物车接口")
    public Result clean(){
        return shoppingCartService.clean();
    }
}
